<%@page contentType="text/html" import="java.sql.*"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<jsp:useBean id="event" scope="session" class="com.asaga.tools.Event_DBImpl" />
<jsp:useBean id="userProfile" scope="session" class="com.asaga.tools.SystemClient_DBImpl" />
<jsp:useBean id="location" scope="session" class="com.asaga.tools.Location_DBImpl" />
<jsp:useBean id="fontBean" scope="session" class="com.asaga.tools.FontBean" />
<jsp:setProperty name="fontBean" property="*" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<% 
String username = (String)session.getAttribute("username");
if(username==null){
    response.sendRedirect("login.jsp?message=Please log in again.");
}
ResultSet myEvents = userProfile.getMyEvents();
ResultSet myPastEvents = userProfile.getMyPastEvents();
%>

<html>
    <%@ include file="header.jsp" %>
    <body>
        <div id="container">
            <%@ include file="topNav.jsp" %>
            <%@ include file="leftside.jsp" %>
            <%@ include file="rightside.jsp" %>
            <div id="content">
                <p id="warning"><jsp:getProperty name="event" property="warningMessage" />
                </p>
                
                <h4 class="heading">My Upcoming Events</h4><br />
                <%if(myEvents == null){%>
                    You have no events created.
               <%}
                else{%>
                <form method="get" action="AutismSiteMasterController">
                        <table class="eventForm">
                            <tr><th></th>
                                <th>Title</th>
                                <th>Start Date</th>
                                <th>Start Time</th>
                                <th>End Time</th>
                            </tr>
                            <% while(myEvents.next()){%>
                            <tr>
                                <td class="selectCell">
                                    <input type="radio" name="eventId" value="<%=myEvents.getInt("eventID")%>" />
                                </td>
                                <td>
                                    <%=myEvents.getString("title")%>
                                </td>
                                <td>
                                    <%=event.revertDate(myEvents.getDate("startDate"))%>
                                </td>
                                <td>
                                    <%=event.revertTime(myEvents.getTime("startTime"))%>
                                </td>
                                <td>
                                    <%=event.revertTime(myEvents.getTime("endTime"))%>
                                </td>
                            </tr>
                      
                        <%}%>
                          </table>
                        <table class="eventForm">
                        <tr><td class="buttonCell">
                                <input type="submit" value="Create Event" name="action" />
                                <input type="submit" value="View Event" name="action" />
                                <input type ="submit" value="Remove Event" name="action" />
                                <input type = "submit" value="Update Event" name="action" />
                            </td>
                        </tr>
                    </table>  
                </form>     
                <%}%>
            </div>
            <div id="content">
                <p id="warning"><jsp:getProperty name="event" property="warningMessage" />
                </p>
                
                <h4 class="heading">My Past Events</h4><br />
                <%if(myEvents == null){%>
                    You have no events created.
               <%}
                else{%>
                <form method="get" action="AutismSiteMasterController">
                        <table class="eventForm">
                            <tr><th></th>
                                <th>Title</th>
                                <th>Start Date</th>
                                <th>Start Time</th>
                                <th>End Time</th>
                            </tr>
                            <% while(myPastEvents.next()){%>
                            <tr>
                                <td class="selectCell">
                                    <input type="radio" name="eventId" value="<%=myPastEvents.getInt("eventID")%>" />
                                </td>
                                <td>
                                    <%=myPastEvents.getString("title")%>
                                </td>
                                <td>
                                    <%=event.revertDate(myPastEvents.getDate("startDate"))%>
                                </td>
                                <td>
                                    <%=event.revertTime(myPastEvents.getTime("startTime"))%>
                                </td>
                                <td>
                                    <%=event.revertTime(myPastEvents.getTime("endTime"))%>
                                </td>
                            </tr>
                      
                        <%}%>
                          </table>
                        <table class="eventForm">
                        <tr><td class="buttonCell">
                                <input type="submit" value="View Event" name="action" />
                                <input type ="submit" value="Remove Event" name="action" />
                                <input type = "submit" value="Update Event" name="action" />
                            </td>
                        </tr>
                    </table>  
                </form>     
                <%}%>
            </div>
            <%@ include file="footer.html" %>
        </div>        
    </body>
</html>
